#ifndef PITA_PLAYER_H_
#define PITA_PLAYER_H_

#include <vector>

#include <boost/bind.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>

#include "interfaces/player_interface.h"

namespace pita
{

	class AudioSinkInterface;
	class AudioSourceInterface;

	class Player : public PlayerInterface
	{
		public:
			template <class Itr>
			Player(AudioSourceInterface& source,
				   Itr sinksBegin,
				   Itr sinksEnd) :
				playing_ (false),
				running_ (true),
				sinks_ (sinksBegin, sinksEnd),
				source_ (&source),
				thread_ (boost::bind(&Player::playFunc, this))
				{}

			~Player();

			void play();
			void pause();
			bool playing() const;

			void shutdown();

		private:
			void playFunc();

		private:
			bool playing_;
			bool running_;
			
			typedef std::vector<AudioSinkInterface*> Sinks;
			Sinks sinks_;

			AudioSourceInterface* source_;

			mutable boost::recursive_mutex mutex_;
			boost::condition condition_;
			boost::thread thread_;
	};

}

#endif
